package com.xplay.xpocker.room.mahjong.dto;

import com.xplay.xpocker.constant.RoomTypeEnum;
import com.xplay.xpocker.dvo.RoomRuleInterface;
import lombok.Data;

import java.util.List;
import java.util.Map;

@Data
public class MahjongRoomRule implements RoomRuleInterface {
    // 总人数
    int userCount;
    // 总局数
    int numberGame;
    int turns;
    int type;
    String roomType;
    String roomTypeStr;
    List<String> rules;
    String ruleStr;

    public String getRuleStr() {
        StringBuffer ruleSB = new StringBuffer();
        if (roomType == null || rules == null) {
            return ruleSB.toString();
        }
        Map<String, String> ruleMap = MahjongRules.INSTANCE.getRules(getRoomType());
        if (ruleMap == null) {
            return ruleSB.toString();
        }
        for (String rule : getRules()) {
            String ruleName = ruleMap.get(rule);
            if (ruleName == null) {
                continue;
            }
            ruleSB.append(ruleName);
            ruleSB.append("、");
        }
        if(ruleSB.length()>0){
            ruleSB.deleteCharAt(ruleSB.length() - 1);
        }
        return ruleSB.toString();
    }


    public String getRoomTypeStr() {
        RoomTypeEnum of = RoomTypeEnum.of(roomType);
        return of != null ? of.name : "";
    }

    /**
     * 判断是否存在某个规则
     * @param rule
     * @return
     */
    @Override
    public boolean checkExistsRule(String... rule){
        if(rules==null || rules.size() == 0){
            return false;
        }
        for (String s : rule) {
            if(!rules.contains(s)){
                return false;
            }
        }
        return true;
    }

}
